<?php

/*
 * 终端域名
 *
 */

class TerminalAction extends BaseAction {
    public function index() {
        $databases_terminal = M('Terminal');
        $where ="";
        $searchtype = $_POST['searchtype'];
        $keyword = $_POST['keyword'];
        $status = $_POST['status'];
        if($_POST['keyword']){
            if($searchtype == "domain_name"){
                $where = "AND `domain_name` LIKE '%$keyword%' ";
            }  else {
                $where="AND $searchtype = $keyword  ";
            }
        }
        if($_POST['status'] !="")$where.="AND status = $status";
        
        if($where) $where = substr($where, 3);
//        dump($where);
        $count = $databases_terminal->where($where)->count();
        import('@.ORG.system_page');
        $p = new Page($count, 15);
        $list = $databases_terminal->where($where)->order('`id` DESC')->limit($p->firstRow . ',' . $p->listRows)->select();
//        echo $databases_terminal->getLastSql();
        
        $this->assign('list',$list);
        $pagebar = $p->show();
        $this->assign('pagebar', $pagebar);
        $this->display();
    }
    
    public function edit(){
        $databases_terminal = M('Terminal');
        $show = $databases_terminal->where(array('id'=>$_GET['id']))->find();
        $this->assign('show',$show);
        $this->display();
    }
    
    public function edit_save(){
        $databases_terminal = M('Terminal');
        unset ($_POST['dosubmit']);
        $info  =  $databases_terminal->save($_POST);
        if($info){
            $this->frame_submit_tips(1,'修改成功！');
        }  else {
            $this->frame_submit_tips(0,'修改失败！请重试~');
        }
    }
    
    

}
